
package com.hlkj.pay.app.merchant.ext.impl.yeepay;
/*
 * Hlpay-Plus aggregate payment system.
 * Copyright (c) 2024-2025 Hlpay Team Copyright has the right of final interpretation.
 */

import java.io.File;
import java.security.PrivateKey;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;

import com.alibaba.fastjson.JSONArray;
import com.hlkj.framework.common.pojo.CommonResult;
import com.hlkj.framework.common.util.id.IdUtils;
import com.hlkj.framework.common.util.json.JsonUtils;
import com.hlkj.framework.extension.annotation.Extension;
import com.hlkj.pay.app.merchant.ext.ChannelMerchantAccessExtPt;
import com.hlkj.pay.app.merchant.ext.MerchantExtConstant;
import com.hlkj.pay.app.merchant.ext.dto.access.*;
import com.hlkj.pay.app.merchant.ext.impl.wxpay.handler.WxPayCommonParamsHandle;
import com.hlkj.pay.app.merchant.ext.impl.yeepay.constant.YeePayRsaUtil;
import com.hlkj.pay.app.merchant.ext.impl.yeepay.dto.MerchantAccessCallBackResponse;
import com.hlkj.pay.app.merchant.ext.impl.yeepay.dto.YeePayAppChannelParams;
import com.hlkj.pay.app.merchant.ext.impl.yeepay.dto.YeePayConfig;
import com.hlkj.pay.app.merchant.ext.impl.yeepay.dto.YeePayReportRecord;
import com.hlkj.pay.app.merchant.ext.impl.yeepay.handler.YeePayCommonParamsHandle;
import com.hlkj.pay.app.merchant.impl.MerchantAccessStatusProcessHandler;
import com.hlkj.pay.dto.merchant.*;
import com.hlkj.pay.dto.pay.PayCommonAppDto;
import com.hlkj.pay.enums.CommonEnum;
import com.hlkj.pay.enums.MerchantEnum;
import com.hlkj.pay.enums.PayEnums;
import com.hlkj.pay.enums.PayOrderEnums;
import com.hlkj.pay.infrastructure.model.merchant.*;
import com.hlkj.pay.infrastructure.model.pay.PayChannelRequestDO;
import com.hlkj.pay.infrastructure.model.pay.ProviderChannelConfigDO;
import com.hlkj.pay.service.pay.IPayChannelDictService;
import com.hlkj.pay.vo.order.req.MerchantProductInfo;
import com.hlkj.pay.vo.order.req.MerchantProductReq;
import com.hlkj.pay.vo.order.resp.MerchantProductQueryResp;
import com.yeepay.yop.sdk.auth.credentials.PKICredentialsItem;
import com.yeepay.yop.sdk.auth.credentials.YopPKICredentials;
import com.yeepay.yop.sdk.base.security.cert.parser.YopCertParserFactory;
import com.yeepay.yop.sdk.config.enums.CertStoreType;
import com.yeepay.yop.sdk.config.provider.file.YopCertConfig;
import com.yeepay.yop.sdk.security.CertTypeEnum;
import com.yeepay.yop.sdk.security.cert.YopCertCategory;
import com.yeepay.yop.sdk.service.aggpay.AggpayClient;
import com.yeepay.yop.sdk.service.aggpay.AggpayClientBuilder;
import com.yeepay.yop.sdk.service.aggpay.model.*;
import com.yeepay.yop.sdk.service.aggpay.request.ReportQueryRequest;
import com.yeepay.yop.sdk.service.aggpay.request.WechatConfigAddSyncRequest;
import com.yeepay.yop.sdk.service.aggpay.request.WechatConfigQueryV2Request;
import com.yeepay.yop.sdk.service.aggpay.response.ReportQueryResponse;
import com.yeepay.yop.sdk.service.aggpay.response.WechatConfigAddSyncResponse;
import com.yeepay.yop.sdk.service.aggpay.response.WechatConfigQueryV2Response;
import com.yeepay.yop.sdk.service.mer.MerClient;
import com.yeepay.yop.sdk.service.mer.MerClientBuilder;
import com.yeepay.yop.sdk.service.mer.model.*;
import com.yeepay.yop.sdk.service.mer.request.*;
import com.yeepay.yop.sdk.service.mer.response.*;
import com.yeepay.yop.sdk.service.sys.SysClient;
import com.yeepay.yop.sdk.service.sys.SysClientBuilder;
import com.yeepay.yop.sdk.service.sys.request.MerchantQualUploadRequest;
import com.yeepay.yop.sdk.service.sys.response.MerchantQualUploadResponse;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.dreamlu.mica.core.utils.StringPool;

/**
 * 易宝进件操作
 */
@Slf4j
@Repository
@RequiredArgsConstructor
@Extension(bizId = MerchantExtConstant.CHANNEL_YEE_PAY)
public class YeePayMerchantAccessExtPt implements ChannelMerchantAccessExtPt {

    private final YeePayCommonParamsHandle yeePayCommonParamsHandle;

    private final IPayChannelDictService payChannelDictService;

    private final MerchantAccessStatusProcessHandler merchantAccessStatusProcessHandler;

    @Value("${hlkj.domain}")
    private String domain;

    private final MerClient api = MerClientBuilder.builder().build();

    private final AggpayClient aggpayApi = AggpayClientBuilder.builder().build();

    @Override
    public void channelConfigCheck(ChannelMerchantAccessCommonContext channelMerchantAccessCommonContext) {

    }

    @Override
    public void merchantAccess(ChannelMerchantAccessContext channelMerchantAccessContext) {
        log.info("易宝渠道提交进件 请求参数:{}", JsonUtils.toJsonString(channelMerchantAccessContext));
        CommonResult<YeePayConfig> yeePayConfigCommonResult = yeePayCommonParamsHandle.yeePayConfig(channelMerchantAccessContext.getProviderChannelConfig(),
                channelMerchantAccessContext.isTest());
        if (!yeePayConfigCommonResult.isSuccess()) {
            channelMerchantAccessContext.setRemark(yeePayConfigCommonResult.getMsg());
            channelMerchantAccessContext.setProcessStatus(false);
            return;
        }
        MerchantAccessDto merchantAccessDto = channelMerchantAccessContext.getMerchantAccessDto();
        MerchantAccessInfoDO merchantAccessInfo = merchantAccessDto.getMerchantAccessInfo();
        // 初始化易宝配置
        YeePayConfig yeePayConfig = yeePayConfigCommonResult.getData();
        // 企业类型
        MerchantEnum.MERCHANT_TYPE merchantType = MerchantEnum.MERCHANT_TYPE.from(merchantAccessInfo.getType());
        switch (merchantType) {
            case PERSONAL:
                yeePayCommonParamsHandle.personAccess(yeePayConfig,channelMerchantAccessContext);
                break;
            default:
                yeePayCommonParamsHandle.companyAccess(yeePayConfig,channelMerchantAccessContext);
        }
    }

    @Override
    public String requestUrl(MerchantAccessDto merchantAccessInfoDO) {
        return null;
    }

    @Override
    public String channelParams(AccessChannelParamsDto accessChannelParamsDto) {
        YeePayAppChannelParams params = new YeePayAppChannelParams();
        params.setSubMchId(accessChannelParamsDto.getSubMchId());
        return JsonUtils.toJsonStringNotNull(params);
    }

    @Override
    public void merchantAccessQuery(ChannelMerchantAccessQueryContext channelMerchantAccessQueryContext) {

        log.info(" 请求参数:{}", JsonUtils.toJsonString(channelMerchantAccessQueryContext));
        CommonResult<YeePayConfig> yeePayConfigCommonResult = yeePayCommonParamsHandle.yeePayConfig(channelMerchantAccessQueryContext.getProviderChannelConfig(),
                channelMerchantAccessQueryContext.isTest());
        if (!yeePayConfigCommonResult.isSuccess()) {
            channelMerchantAccessQueryContext.setRemark(yeePayConfigCommonResult.getMsg());
            channelMerchantAccessQueryContext.setProcessStatus(false);
            return;
        }
        // 进件信息
        MerchantAccessInfoDO merchantAccessInfo = channelMerchantAccessQueryContext.getMerchantAccessInfo();
        // 易宝配置信息
        YeePayConfig yeePayConfig = yeePayConfigCommonResult.getData();

        try{
            String applymentId = merchantAccessInfo.getRequestId();
            if(StrUtil.isEmpty(applymentId)){
                channelMerchantAccessQueryContext.setRemark("易宝查询进件 参数applyment_id is null");
                channelMerchantAccessQueryContext.setProcessStatus(false);
                return;
            }
            // 请求
            RegisterQueryV2Request request = new RegisterQueryV2Request();
            String appKey = yeePayConfig.getAppId();
            request.getRequestConfig().setAppKey(appKey);
            request.getRequestConfig().setCredentials(new YopPKICredentials(
                    appKey, new PKICredentialsItem(getPrivateKey(
                    yeePayConfig.getPrivateKey(),
                    CertTypeEnum.RSA2048),
                    CertTypeEnum.RSA2048)));

            request.setRequestNo(applymentId);
            RegisterQueryV2Response response = api.registerQueryV2(request);
            log.info("易宝查询进件 返回参数:{}", response);

            RegisterQueryV2NetInProgressQueryRespDtoResult yeePayAccessQueryResp = response.getResult();
            if(!"NIG00000".equals(yeePayAccessQueryResp.getReturnCode())){
                channelMerchantAccessQueryContext.setProcessStatus(false);
                channelMerchantAccessQueryContext.setRemark(yeePayAccessQueryResp.getReturnMsg());
                return;
            }

            // 商户编号
            if(StrUtil.isNotEmpty(yeePayAccessQueryResp.getMerchantNo())){
                merchantAccessInfo.setSubMchId(yeePayAccessQueryResp.getMerchantNo());
            }

            // 待签约会返回 特约商户号 和 商户链接
            if(StrUtil.isNotEmpty(yeePayAccessQueryResp.getElecSignUrl())){
                MerchantAccessSignLink signLink = new MerchantAccessSignLink();
                signLink.setLink(yeePayAccessQueryResp.getElecSignUrl());
                channelMerchantAccessQueryContext.setSignLinks(CollUtil.newArrayList(signLink));
            }

            /**
             * 审核状态转换
             * 系统审核状态 0：草稿 1：鉴权中 2：已提交，等待平台审核，3：系统自动审核中，4：系统审核通过渠道审核中，5：平台审核中，6：待签约，7：签约中，8：待配置，9：配置中，10：审核完成，11：审核驳回
             * 易宝进件审核状态如下：
             * REVIEWING               申请审核中  -> 平台审核中
             * REVIEW_BACK             申请已驳回  -> 审核驳回
             * AUTHENTICITY_VERIFYING  真实性验证  -> 平台审核中
             * AGREEMENT_SIGNING       协议待签署  -> 配置中
             * BUSINESS_OPENING        业务开通中  -> 待签约/签约中
             * COMPLETED               申请已完成  -> 审核完成
             */
            switch (yeePayAccessQueryResp.getApplicationStatus()) {
                case "REVIEW_BACK":
                    channelMerchantAccessQueryContext.setProcessStatus(false);
                    channelMerchantAccessQueryContext.setAccessStatus(MerchantEnum.ACCESS_STATUS.APPROVE_REFUSE);
                    channelMerchantAccessQueryContext.setRemark(yeePayAccessQueryResp.getAuditOpinion());
                    break;
                case "REVIEWING":
                case "AUTHENTICITY_VERIFYING":
                    channelMerchantAccessQueryContext.setAccessStatus(MerchantEnum.ACCESS_STATUS.CHANNEL_APPROVE);
                    break;
                case "AGREEMENT_SIGNING":
                    channelMerchantAccessQueryContext.setAccessStatus(MerchantEnum.ACCESS_STATUS.WAIT_SIGN);
                    channelMerchantAccessQueryContext.setAuditStatus(MerchantEnum.CHANNEL_CONFIG_STATUS.CONTINUE_APPLY_QUERY);
                    break;
                case "BUSINESS_OPENING":
                case "COMPLETED":
                    channelMerchantAccessQueryContext.setAccessStatus(MerchantEnum.ACCESS_STATUS.APPROVE_SUCCESS);
                    channelMerchantAccessQueryContext.setAuditStatus(MerchantEnum.CHANNEL_CONFIG_STATUS.SUBMIT);
                    break;
                default:
                    channelMerchantAccessQueryContext.setProcessStatus(false);
                    channelMerchantAccessQueryContext.setRemark(response.getResult().getReturnMsg());
                    break;
            }

        }catch (Exception e){
            e.printStackTrace();
            channelMerchantAccessQueryContext.setProcessStatus(false);
            channelMerchantAccessQueryContext.setRemark(e.getMessage());
        }
    }

    @Override
    public void merchantSign(ChannelMerchantAccessSignContext channelMerchantAccessSignContext) {
    }

    @Override
    public void merchantSignQuery(ChannelMerchantAccessSignContext channelMerchantAccessSignContext) {
    }

    @Override
    public void merchantBusinessOpen(ChannelMerchantBusinessContext channelMerchantBusinessContext) {
    }

    @Override
    public void wechatConfigInit(ChannelMerchantBusinessContext channelMerchantBusinessContext) {

        CommonResult<YeePayConfig> yeePayConfigCommonResult = yeePayCommonParamsHandle.yeePayConfig(channelMerchantBusinessContext.getProviderChannelConfig(),
                channelMerchantBusinessContext.isTest());
        if (!yeePayConfigCommonResult.isSuccess()) {
            channelMerchantBusinessContext.setRemark(yeePayConfigCommonResult.getMsg());
            channelMerchantBusinessContext.setProcessStatus(false);
            return;
        }
        YeePayConfig yeePayConfig = yeePayConfigCommonResult.getData();
        // 1. 数据初始化
        MerchantAccessInfoDO merchantAccessInfo = channelMerchantBusinessContext.getMerchantAccessDto().getMerchantAccessInfo();
        try {
            List<PayCommonAppDto> payCommonAppList = channelMerchantBusinessContext.getPayCommonAppList();
            List<PayCommonAppDto> wechatCommonApp = null;
            if (!CollectionUtils.isEmpty(payCommonAppList)) {
                wechatCommonApp = payCommonAppList.stream().filter(payCommonAppDto -> PayEnums.PAY_TYPE.WECHAT.getCode().equals(payCommonAppDto.getPayWayDO().getType()))
                        .collect(Collectors.toList());
            }
            // 没有微信执行 配置完成
            if (CollectionUtils.isEmpty(wechatCommonApp)) {
                // channelMerchantBusinessContext.setAuditStatus(MerchantEnum.CHANNEL_CONFIG_STATUS.ALIPAY_AUTH);
                return;
            }

            if (!domain.endsWith(StringPool.SLASH)) {
                domain = domain + StringPool.SLASH;
            }

            WechatConfigAddSyncRequest request = new WechatConfigAddSyncRequest();
            String appKey = yeePayConfig.getAppId();
            request.getRequestConfig().setAppKey(appKey);
            request.getRequestConfig().setCredentials(new YopPKICredentials(
                    appKey, new PKICredentialsItem(getPrivateKey(
                    yeePayConfig.getPrivateKey(),
                    CertTypeEnum.RSA2048),
                    CertTypeEnum.RSA2048)));

            WechatConfigFlatRequestDTO wechatConfigFlatRequestDTO = new WechatConfigFlatRequestDTO();
            // 支付授权目录列表
            wechatConfigFlatRequestDTO.setTradeAuthDirList(JSONUtil.toJsonStr(CollUtil.newArrayList(domain)));
            // 支付appId目录列表
            List<Map<String,String>> appIdList = new ArrayList<>();
            for(PayCommonAppDto commonAppDto:wechatCommonApp){
                Map<String,String> appIdMap = new HashMap<>();
                appIdMap.put("appId",commonAppDto.getAppId());
                if(commonAppDto.getType() == 1){
                    appIdMap.put("appIdType","OFFICIAL_ACCOUNT");
                }else{
                    appIdMap.put("appIdType","MINI_PROGRAM");
                }
                appIdList.add(appIdMap);
            }

            wechatConfigFlatRequestDTO.setAppIdList(JSONUtil.toJsonStr(appIdList));
            wechatConfigFlatRequestDTO.setMerchantNo(merchantAccessInfo.getSubMchId());
            request.setBody(wechatConfigFlatRequestDTO);

            WechatConfigAddSyncResponse response = aggpayApi.wechatConfigAddSync(request);
            log.info("易宝 微信参数初始化配置 返回参数 :{}", JsonUtils.toJsonString(response.getResult()));
            if("00000".equals(response.getResult().getCode())){
                log.info("易宝 微信参数初始化配置 成功 返回参数 :{}", JsonUtils.toJsonString(response.getResult()));
            }else{
                log.info("易宝 微信参数初始化配置 失败 返回参数 :{}", JsonUtils.toJsonString(response.getResult()));
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            log.error("易宝微信配置init请求失败,失败信息 message: {}", e.getMessage());
            channelMerchantBusinessContext.setRemark("易宝微信配置init请求失败,失败信息" + e.getMessage());
            channelMerchantBusinessContext.setProcessStatus(Boolean.FALSE);
        }
        channelMerchantBusinessContext.setAuditStatus(MerchantEnum.CHANNEL_CONFIG_STATUS.FINISH);
    }


    @Override
    public void wechatConfigAdd(ChannelMerchantBusinessContext channelMerchantBusinessContext) {

        CommonResult<YeePayConfig> yeePayConfigCommonResult = yeePayCommonParamsHandle.yeePayConfig(channelMerchantBusinessContext.getProviderChannelConfig(),
                channelMerchantBusinessContext.isTest());
        if (!yeePayConfigCommonResult.isSuccess()) {
            channelMerchantBusinessContext.setRemark(yeePayConfigCommonResult.getMsg());
            channelMerchantBusinessContext.setProcessStatus(false);
            return;
        }
        YeePayConfig yeePayConfig = yeePayConfigCommonResult.getData();
        // 1. 数据初始化
        PayChannelRequestDO payChannelRequestDO = new PayChannelRequestDO();
        channelMerchantBusinessContext.setPayChannelRequestDO(payChannelRequestDO);
        MerchantAccessInfoDO merchantAccessInfo = channelMerchantBusinessContext.getMerchantAccessDto().getMerchantAccessInfo();
        MerchantWechatConfigDto merchantWechatConfigDto = channelMerchantBusinessContext.getMerchantWechatConfigDto();
        try {

            WechatConfigAddSyncRequest request = new WechatConfigAddSyncRequest();
            String appKey = yeePayConfig.getAppId();
            request.getRequestConfig().setAppKey(appKey);
            request.getRequestConfig().setCredentials(new YopPKICredentials(
                    appKey, new PKICredentialsItem(getPrivateKey(
                    yeePayConfig.getPrivateKey(),
                    CertTypeEnum.RSA2048),
                    CertTypeEnum.RSA2048)));

            WechatConfigFlatRequestDTO wechatConfigFlatRequestDTO = new WechatConfigFlatRequestDTO();
            wechatConfigFlatRequestDTO.setMerchantNo(merchantAccessInfo.getSubMchId());
            // 支付授权目录列表
            String jsAPIPath = merchantWechatConfigDto.getJsAPIPath();
            if(StrUtil.isNotEmpty(jsAPIPath)){
                wechatConfigFlatRequestDTO.setTradeAuthDirList(JSONUtil.toJsonStr(CollUtil.newArrayList(jsAPIPath)));
            }
            // 支付appId目录列表
            String appId = merchantWechatConfigDto.getAppId();
            if(StrUtil.isNotEmpty(appId)){
                List<Map<String,String>> appIdList = new ArrayList<>();
                Map<String,String> appIdMap = new HashMap<>();
                appIdMap.put("appId",appId);
                appIdMap.put("appIdType","OFFICIAL_ACCOUNT");
                appIdList.add(appIdMap);
                wechatConfigFlatRequestDTO.setAppIdList(JSONUtil.toJsonStr(appIdList));
            }

            request.setBody(wechatConfigFlatRequestDTO);

            log.info("易宝 微信配置add 请求参数 :{}", JsonUtils.toJsonString(request));
            WechatConfigAddSyncResponse response = aggpayApi.wechatConfigAddSync(request);
            WechatConfigFlatResponseDTO result = response.getResult();
            log.info("易宝 微信配置add 返回参数 :{}", JsonUtils.toJsonString(response.getResult()));

            if("00000".equals(response.getResult().getCode())){
                log.info("易宝 微信配置 add 配置 成功 返回参数 :{}", JsonUtils.toJsonString(response.getResult()));
                Map<String,String> failMap = new HashMap<>();
                if(result.getStatus().equals("FAILED")){
                    List<ConfigMerchantDTO> configResponseList = JSONUtil.toList(result.getConfigResult(), ConfigMerchantDTO.class);
                    if(CollUtil.isNotEmpty(configResponseList)){
                        ConfigMerchantDTO configMerchantDTO = configResponseList.get(0);
                        // 微信公众号授权目录
                        if(CollUtil.isNotEmpty(configMerchantDTO.getTradeAuthDirList())){
                            TradeAuthDirDTO tradeAuthDirDTO = configMerchantDTO.getTradeAuthDirList().get(0);
                            if(tradeAuthDirDTO.getStatus().equals("FAILED")){
                                failMap.put(tradeAuthDirDTO.getTradeAuthDir(),tradeAuthDirDTO.getFailReason());
                            }
                        }
                        // AppID
                        if(CollUtil.isNotEmpty(configMerchantDTO.getAppIdList())){
                            AppIdConfigDetail appIdConfigDetail = configMerchantDTO.getAppIdList().get(0);
                            if(appIdConfigDetail.getStatus().equals("FAILED")){
                                failMap.put(appIdConfigDetail.getAppId(),appIdConfigDetail.getFailReason());
                            }
                        }
                    }
                }
                if(MapUtil.isNotEmpty(failMap)){
                    channelMerchantBusinessContext.setProcessStatus(Boolean.FALSE);
                    channelMerchantBusinessContext.setRemark(JSONUtil.toJsonPrettyStr(failMap));
                }
            }else{
                channelMerchantBusinessContext.setProcessStatus(Boolean.FALSE);
                channelMerchantBusinessContext.setRemark(response.getResult().getMessage());
                log.info("易宝 微信配置 add 配置 失败 返回参数 :{}", JsonUtils.toJsonString(response.getResult()));
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            log.error("易宝微信配置add请求失败,失败信息 message: {}", e.getMessage());
            channelMerchantBusinessContext.setRemark("易宝微信配置add请求失败,失败信息" + e.getMessage());
            channelMerchantBusinessContext.setProcessStatus(Boolean.FALSE);
            // channelMerchantBusinessContext.setAccessStatus(MerchantEnum.ACCESS_STATUS.APPROVE_REFUSE);
        }

    }

    @Override
    public void wechatConfigQuery(ChannelMerchantAccessAuthQueryContext channelMerchantAccessAuthQueryContext) {

        CommonResult<YeePayConfig> yeePayConfigCommonResult = yeePayCommonParamsHandle.yeePayConfig(channelMerchantAccessAuthQueryContext.getProviderChannelConfig(),
                channelMerchantAccessAuthQueryContext.isTest());
        if (!yeePayConfigCommonResult.isSuccess()) {
            channelMerchantAccessAuthQueryContext.setRemark(yeePayConfigCommonResult.getMsg());
            channelMerchantAccessAuthQueryContext.setProcessStatus(false);
            return;
        }
        YeePayConfig yeePayConfig = yeePayConfigCommonResult.getData();
        // 1. 数据初始化
        MerchantAccessInfoDO merchantAccessInfo = channelMerchantAccessAuthQueryContext.getMerchantAccessInfo();
        try {

            WechatConfigQueryV2Request request = new WechatConfigQueryV2Request();
            String appKey = yeePayConfig.getAppId();
            request.getRequestConfig().setAppKey(appKey);
            request.getRequestConfig().setCredentials(new YopPKICredentials(
                    appKey, new PKICredentialsItem(getPrivateKey(
                    yeePayConfig.getPrivateKey(),
                    CertTypeEnum.RSA2048),
                    CertTypeEnum.RSA2048)));
            request.setMerchantNo(merchantAccessInfo.getSubMchId());

            WechatConfigQueryV2Response response = aggpayApi.wechatConfigQueryV2(request);
            WechatConfigFlatResponseDTO result = response.getResult();
            if("00000".equals(result.getCode())){
                List<ConfigMerchantDTO> configResponseList = JSONUtil.toList(result.getConfigResult(), ConfigMerchantDTO.class);
                if(CollUtil.isNotEmpty(configResponseList)){
                    ConfigMerchantDTO configResponseDTO = configResponseList.get(0);

                    if (configResponseDTO != null) {
                        MerchantWechatConfigListDto merchantWechatConfigListDto = new MerchantWechatConfigListDto();
                        merchantWechatConfigListDto.setAppIdList(CollUtil.newArrayList());
                        merchantWechatConfigListDto.setJsApiPath(CollUtil.newArrayList());
                        if (CollUtil.isNotEmpty(configResponseDTO.getAppIdList())) {
                            for (AppIdConfigDetail appIdConfigDetail : configResponseDTO.getAppIdList()) {
                                MerchantWechatConfigAppIdDto merchantWechatConfigAppIdDto = new MerchantWechatConfigAppIdDto();
                                merchantWechatConfigAppIdDto.setSubAppid(appIdConfigDetail.getAppId());
                                merchantWechatConfigAppIdDto.setSubscribeAppid(appIdConfigDetail.getSubscribeAppId());
                                merchantWechatConfigListDto.getAppIdList().add(merchantWechatConfigAppIdDto);
                            }
                        }
                        if (CollUtil.isNotEmpty(configResponseDTO.getTradeAuthDirList())) {
                            for (TradeAuthDirDTO tradeAuthDirDTO : configResponseDTO.getTradeAuthDirList()) {
                                merchantWechatConfigListDto.getJsApiPath().add(tradeAuthDirDTO.getTradeAuthDir());
                            }
                        }
                        channelMerchantAccessAuthQueryContext.setMerchantWechatConfigListDto(merchantWechatConfigListDto);
                    }
                }

            }else{
                log.error("易宝微信配置查询请求失败,失败信息 message: {}", result.getMessage());
            }
            // 易宝 微信 不需要报备
            channelMerchantAccessAuthQueryContext.setAuditStatus(MerchantEnum.CHANNEL_CONFIG_STATUS.FINISH);
        }
        catch (Exception e) {
            e.printStackTrace();
            log.error("易宝微信配置查询请求失败,失败信息 message: {}", e.getMessage());
            channelMerchantAccessAuthQueryContext.setRemark("易宝微信配置查询请求失败,失败信息" + e.getMessage());
            channelMerchantAccessAuthQueryContext.setProcessStatus(Boolean.FALSE);
        }


    }

    @Override
    public void wechatAuthConfig(ChannelMerchantBusinessContext channelMerchantBusinessContext) {

        CommonResult<YeePayConfig> yeePayConfigCommonResult = yeePayCommonParamsHandle.yeePayConfig(channelMerchantBusinessContext.getProviderChannelConfig(),
                channelMerchantBusinessContext.isTest());
        if (!yeePayConfigCommonResult.isSuccess()) {
            channelMerchantBusinessContext.setRemark(yeePayConfigCommonResult.getMsg());
            channelMerchantBusinessContext.setProcessStatus(false);
            return;
        }
        YeePayConfig yeePayConfig = yeePayConfigCommonResult.getData();

        try{
            // 数据初始化
            MerchantAccessInfoDO merchantAccessInfo = channelMerchantBusinessContext.getMerchantAccessDto().getMerchantAccessInfo();
            // 法人信息
            MerchantAccessCertInfoDO merchantAccessLegal = channelMerchantBusinessContext.getMerchantAccessDto().getMerchantAccessLegal();
            // 联系人信息
            MerchantAccessCertInfoDO merchantAccessContact = channelMerchantBusinessContext.getMerchantAccessDto().getMerchantAccessContact();
            // 主体信息
            MerchantAccessLicenseDO merchantAccessLicenseDO = channelMerchantBusinessContext.getMerchantAccessDto().getMerchantAccessLicense();
            // 经营信息
            MerchantAccessBusinessDO merchantAccessBusinessDO = channelMerchantBusinessContext.getMerchantAccessDto().getMerchantAccessBusiness();

            // 主体是否企业
            boolean enterprise = MerchantEnum.MERCHANT_TYPE.COMPANY.getCode() == merchantAccessInfo.getType() ? true : false;

            MerchantWechatauthApplyRequest request = new MerchantWechatauthApplyRequest();
            String appKey = yeePayConfig.getAppId();
            request.getRequestConfig().setAppKey(appKey);
            request.getRequestConfig().setCredentials(new YopPKICredentials(
                    appKey, new PKICredentialsItem(getPrivateKey(
                    yeePayConfig.getPrivateKey(),
                    CertTypeEnum.RSA2048),
                    CertTypeEnum.RSA2048)));

            request.setRequestNo(IdUtils.getSnowflakeNextIdStr());
            request.setSubMerchantNo(merchantAccessInfo.getSubMchId());

            // 判断是否经办人
            if(!CommonEnum.YES_NO_TYPE.YES.getCode().equals(merchantAccessInfo.getContactType() )){
                request.setApplicantType("TRANSACTOR");
                request.setApplicantName(merchantAccessContact.getName());
                request.setApplicantIdCard(merchantAccessContact.getCertNo());

                Map<String,Object> transactorInfo = new HashMap<>();
                // 经营场景类的其他的文件 第一个文件是否上传(业务办理授权函)
                List<String> fileUrls =  channelMerchantBusinessContext.getMerchantAccessDto().getMerchantAccessBusiness().getFileUrls();
                if(CollUtil.isEmpty(fileUrls)){
                    // 直接结束
                    channelMerchantBusinessContext.setRemark("业务办理授权函未上传");
                    channelMerchantBusinessContext.setProcessStatus(false);
                    return;
                }
                transactorInfo.put("businessAuthorizationLetter",yeePayCommonParamsHandle.getUploadMerQualUrl(fileUrls.get(0),yeePayConfig));
                transactorInfo.put("transactorIdentificationBackCopy",yeePayCommonParamsHandle.getUploadMerQualUrl(merchantAccessContact.getCertBackUrl(),yeePayConfig));
                transactorInfo.put("transactorIdentificationFrontCopy",yeePayCommonParamsHandle.getUploadMerQualUrl(merchantAccessContact.getCertFrontUrl(),yeePayConfig));
                transactorInfo.put("transactorIdentificationType",yeePayCommonParamsHandle.certType(merchantAccessContact.getCertType()));
                // 永久
                if(merchantAccessContact.getCertValidityType() == 1){
                    transactorInfo.put("transactorIdentificationValidDate",CollUtil.newArrayList(merchantAccessContact.getCertBeginDate(),"forever"));
                }else{
                    transactorInfo.put("transactorIdentificationValidDate",CollUtil.newArrayList(merchantAccessContact.getCertBeginDate(),merchantAccessLegal.getCertEndDate()));
                }
                request.setTransactorInfo(JSONUtil.toJsonStr(transactorInfo));

            }else{
                request.setApplicantType("LEGAL");
                request.setApplicantName(merchantAccessLegal.getName());
                request.setApplicantPhone(merchantAccessLegal.getPhone());
            }

            // 主体为企业
            if(enterprise){
                request.setIdentificationAddress(merchantAccessLegal.getAddress());
                request.setCertCopy(yeePayCommonParamsHandle.getUploadMerQualUrl(merchantAccessLicenseDO.getLicenseUrl(),yeePayConfig));
                if(merchantAccessLicenseDO.getLicenseValidityType() == 1){
                    request.setLicenceValidDate(JSONUtil.toJsonStr(CollUtil.newArrayList(merchantAccessLicenseDO.getLicenseBeginDate(),"forever")));;
                }else{
                    request.setLicenceValidDate(JSONUtil.toJsonStr(CollUtil.newArrayList(merchantAccessLicenseDO.getLicenseBeginDate(),merchantAccessLicenseDO.getLicenseEndDate())));;
                }
                request.setOwner(true);
                JSONArray uboArray = yeePayCommonParamsHandle.getWxUnoArray(channelMerchantBusinessContext.getMerchantAccessDto().getMerchantAccessBenefitList(),yeePayConfig);
                if(!uboArray.isEmpty()){
                    request.setUboInfoList(JSONUtil.toJsonStr(uboArray));
                }
                request.setCertType(yeePayCommonParamsHandle.licenseType(merchantAccessLicenseDO.getLicenseType()));
                request.setCertNumber(merchantAccessLicenseDO.getLicenseCode());
            }else{
                // 小微
                request.setMicroBizType("MICRO_TYPE_STORE");
                request.setStoreName(merchantAccessBusinessDO.getShortName());
                request.setStoreAddressCode(merchantAccessBusinessDO.getCityCode());
                request.setStoreHeaderCopy(yeePayCommonParamsHandle.getUploadMerQualUrl(merchantAccessBusinessDO.getStoreHeaderUrl(),yeePayConfig));
                request.setStoreIndoorCopy(yeePayCommonParamsHandle.getUploadMerQualUrl(merchantAccessBusinessDO.getStoreIndoorUrl(),yeePayConfig));
            }

            // 永久
            if(merchantAccessLegal.getCertValidityType() == 1){
                request.setIdentificationValidDate(JSONUtil.toJsonStr(CollUtil.newArrayList(merchantAccessLegal.getCertBeginDate(),"forever")));
            }else{
                request.setIdentificationValidDate(JSONUtil.toJsonStr(CollUtil.newArrayList(merchantAccessLegal.getCertBeginDate(),merchantAccessLegal.getCertEndDate())));
            }
            request.setCompanyAddress(merchantAccessLegal.getAddress());

            // 费率
            request.setReportFee("XIANXIA");

            MerchantWechatauthApplyResponse response = api.merchantWechatauthApply(request);
            MerchantWechatauthApplyApplymentRespDtoResult result = response.getResult();
            if("BMS00000".equals(result.getReturnCode())){
                // 获取申请单编号
                String applymentId = result.getApplymentId();
                channelMerchantBusinessContext.setExtendA(applymentId);
                channelMerchantBusinessContext.setAuditStatus(MerchantEnum.CHANNEL_CONFIG_STATUS.WECHAT_AUTHING);
            }else{
                log.error("易宝微信认证配置失败：{}",result.getReturnMsg());
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            log.error("易宝微信配置查询请求失败,失败信息 message: {}", e.getMessage());
            channelMerchantBusinessContext.setRemark("易宝微信配置查询请求失败,失败信息" + e.getMessage());
            channelMerchantBusinessContext.setProcessStatus(Boolean.FALSE);
        }
    }

    @Override
    public boolean authConfigQueryType() {
        return false;
    }

    @Override
    public void wechatAuthQuery(ChannelMerchantAccessAuthQueryContext channelMerchantAccessAuthQueryContext) {
        try {
            // 要查询的场景集合
            List<String> sceneList = CollUtil.newArrayList("ONLINE","OFFLINE");
            // 查询报备信息
            List<MerchantAccessAuthDO> merchantAccessAuthList = getReportRecordList(channelMerchantAccessAuthQueryContext,PayEnums.PAY_TYPE.WECHAT,sceneList);
            channelMerchantAccessAuthQueryContext.setAuditStatus(MerchantEnum.CHANNEL_CONFIG_STATUS.ALIPAY_AUTH);
            channelMerchantAccessAuthQueryContext.setMerchantAccessAuthList(merchantAccessAuthList);
        }
        catch (Exception e) {
            e.printStackTrace();
            log.error("易宝微信报备查询查询请求失败,失败信息 message: {}", e.getMessage());
            channelMerchantAccessAuthQueryContext.setRemark("易宝微信报备查询查询请求失败,失败信息" + e.getMessage());
            channelMerchantAccessAuthQueryContext.setProcessStatus(Boolean.FALSE);
        }
    }

    @Override
    public void alipayAuthConfig(ChannelMerchantBusinessContext channelMerchantBusinessContext) {

        CommonResult<YeePayConfig> yeePayConfigCommonResult = yeePayCommonParamsHandle.yeePayConfig(channelMerchantBusinessContext.getProviderChannelConfig(),
                channelMerchantBusinessContext.isTest());
        if (!yeePayConfigCommonResult.isSuccess()) {
            channelMerchantBusinessContext.setRemark(yeePayConfigCommonResult.getMsg());
            channelMerchantBusinessContext.setProcessStatus(false);
            return;
        }
        YeePayConfig yeePayConfig = yeePayConfigCommonResult.getData();

        try{
            // 数据初始化
            MerchantAccessInfoDO merchantAccessInfo = channelMerchantBusinessContext.getMerchantAccessDto().getMerchantAccessInfo();
            // 法人信息
            MerchantAccessCertInfoDO merchantAccessLegal = channelMerchantBusinessContext.getMerchantAccessDto().getMerchantAccessLegal();
            // 联系人信息
            MerchantAccessCertInfoDO merchantAccessContact = channelMerchantBusinessContext.getMerchantAccessDto().getMerchantAccessContact();
            // 主体信息
            MerchantAccessLicenseDO merchantAccessLicenseDO = channelMerchantBusinessContext.getMerchantAccessDto().getMerchantAccessLicense();
            // 经营信息
            MerchantAccessBusinessDO merchantAccessBusinessDO = channelMerchantBusinessContext.getMerchantAccessDto().getMerchantAccessBusiness();
            // 主体是否企业
            boolean enterprise = MerchantEnum.MERCHANT_TYPE.COMPANY.getCode() == merchantAccessInfo.getType() ? true : false;

            AlipayauthApplyRequest request = new AlipayauthApplyRequest();
            String appKey = yeePayConfig.getAppId();
            request.getRequestConfig().setAppKey(appKey);
            request.getRequestConfig().setCredentials(new YopPKICredentials(
                    appKey, new PKICredentialsItem(getPrivateKey(
                    yeePayConfig.getPrivateKey(),
                    CertTypeEnum.RSA2048),
                    CertTypeEnum.RSA2048)));

            IdentityAuthApplymentReqDto identityAuthApplymentReqDto = new IdentityAuthApplymentReqDto();
            identityAuthApplymentReqDto.setMerchantNo(merchantAccessInfo.getSubMchId());
            identityAuthApplymentReqDto.setRequestNo(IdUtils.getSnowflakeNextIdStr());

            // 联系人信息
            IdentityAuthContactInfo identityAuthContactInfo = new IdentityAuthContactInfo();
            // 判断是否经办人
            if(!CommonEnum.YES_NO_TYPE.YES.getCode().equals(merchantAccessInfo.getContactType() )){
                // 经营场景类的其他的文件 第一个文件是否上传(业务办理授权函)
                List<String> fileUrls =  channelMerchantBusinessContext.getMerchantAccessDto().getMerchantAccessBusiness().getFileUrls();
                if(CollUtil.isEmpty(fileUrls)){
                    channelMerchantBusinessContext.setRemark("业务办理授权函未上传");
                    channelMerchantBusinessContext.setProcessStatus(false);
                    return;
                }
                identityAuthContactInfo.setContactType("SUPER");
                identityAuthContactInfo.setContactPhone(merchantAccessContact.getPhone());
                identityAuthContactInfo.contactName(merchantAccessContact.getName());
                identityAuthContactInfo.setContactIdCard(merchantAccessContact.getCertNo());
                identityAuthContactInfo.setContactType(WxPayCommonParamsHandle.certType(merchantAccessContact.getCertType()));
                identityAuthContactInfo.setContactIdentificationFrontCopy(yeePayCommonParamsHandle.getUploadMerQualUrl(merchantAccessContact.getCertFrontUrl(),yeePayConfig));
                identityAuthContactInfo.setContactIdentificationBackCopy(yeePayCommonParamsHandle.getUploadMerQualUrl(merchantAccessContact.getCertBackUrl(),yeePayConfig));
                identityAuthContactInfo.setContactIdentificationStartTime(merchantAccessContact.getCertBeginDate());
                // 永久
                if(merchantAccessContact.getCertValidityType() == 1){
                    identityAuthContactInfo.setContactIdentificationEndTime("forever");
                }else{
                    identityAuthContactInfo.setContactIdentificationEndTime(merchantAccessContact.getCertEndDate());
                }

            }else{
                identityAuthContactInfo.setContactType("LEGAL");
                identityAuthContactInfo.setContactPhone(merchantAccessLegal.getPhone());
                identityAuthContactInfo.contactName(merchantAccessLegal.getName());
                identityAuthContactInfo.setContactIdCard(merchantAccessLegal.getCertNo());
            }
            identityAuthApplymentReqDto.setContactInfo(identityAuthContactInfo);

            // 主体信息
            IdentityAuthSubjectInfo subjectInfo = new IdentityAuthSubjectInfo();
            subjectInfo.setCompanyAddress(merchantAccessLicenseDO.getAddress());
            subjectInfo.setLicenceValidStartDate(merchantAccessLicenseDO.getLicenseBeginDate());
            if(merchantAccessLicenseDO.getLicenseValidityType() == 1){
                subjectInfo.setLicenceValidEndDate("forever");
            }else{
                subjectInfo.setLicenceValidEndDate(merchantAccessLicenseDO.getLicenseEndDate());
            }
            identityAuthApplymentReqDto.setSubjectInfo(subjectInfo);

            // 法人信息
            IdentityAuthIdentificationInfo identificationInfo = new IdentityAuthIdentificationInfo();
            identificationInfo.setIdentificationStartTime(merchantAccessLegal.getCertBeginDate());
            if(merchantAccessLegal.getCertValidityType() == 1){
                identificationInfo.setIdentificationEndTime("forever");
            }else{
                identificationInfo.setIdentificationEndTime(merchantAccessLegal.getCertEndDate());
            }
            if(enterprise){
                identificationInfo.setIdentificationAddress(merchantAccessLegal.getAddress());
            }
            identificationInfo.setOwner(true);

            identityAuthApplymentReqDto.setIdentificationInfo(identificationInfo);
            // 费率
            identityAuthApplymentReqDto.setReportFee("ALIPUTONG");

            JSONArray uboArray = yeePayCommonParamsHandle.getAliUnoArray(channelMerchantBusinessContext.getMerchantAccessDto().getMerchantAccessBenefitList(),yeePayConfig);
            if(enterprise && !uboArray.isEmpty()){
                identityAuthApplymentReqDto.setUboInfoList(JSONUtil.toList(uboArray.toJSONString(),IdentityAuthUboInfo.class));
            }

            // 小微商户辅助材料证明信息（小微商户必填）
            if(!enterprise){
                IdentityAuthAssistProveInfo assistProveInfo = new IdentityAuthAssistProveInfo();
                assistProveInfo.setMicroBizType("MICRO_TYPE_MOBILE");
                assistProveInfo.setStoreName(merchantAccessBusinessDO.getShortName());
                assistProveInfo.setProvinceCode(merchantAccessBusinessDO.getProvinceCode());
                assistProveInfo.setCityCode(merchantAccessBusinessDO.getCityCode());
                assistProveInfo.setDisitrictCode(merchantAccessBusinessDO.getAreaCode());
                assistProveInfo.setStoreAddress(merchantAccessBusinessDO.getAddress());
                assistProveInfo.setStoreHeaderCopy(yeePayCommonParamsHandle.getUploadMerQualUrl(merchantAccessBusinessDO.getStoreHeaderUrl(),yeePayConfig));
                assistProveInfo.setStoreIndoorCopy(yeePayCommonParamsHandle.getUploadMerQualUrl(merchantAccessBusinessDO.getStoreIndoorUrl(),yeePayConfig));
                identityAuthApplymentReqDto.setAssistProveInfo(assistProveInfo);
            }

            request.setBody(identityAuthApplymentReqDto);

            AlipayauthApplyResponse response = api.alipayauthApply(request);

            IdentityAuthApplymentRespDto result = response.getResult();
            if("BMS00000".equals(result.getReturnCode())){
                // 获取申请单编号
                String applymentId = result.getApplymentId();
                channelMerchantBusinessContext.setExtendB(applymentId);
            }else{
                log.info("易宝 支付宝认证查询 返回异常 :{}", JsonUtils.toJsonString(response));
            }
            channelMerchantBusinessContext.setAuditStatus(MerchantEnum.CHANNEL_CONFIG_STATUS.ALIPAY_AUTHING);

        }
        catch (Exception e) {
            e.printStackTrace();
            log.error("易宝微信配置查询请求失败,失败信息 message: {}", e.getMessage());
            channelMerchantBusinessContext.setRemark("易宝微信配置查询请求失败,失败信息" + e.getMessage());
            channelMerchantBusinessContext.setProcessStatus(Boolean.FALSE);
        }
    }

    @Override
    public void alipayAuthQuery(ChannelMerchantAccessAuthQueryContext channelMerchantAccessAuthQueryContext) {
        try {
            // 要查询的场景集合
            List<String> sceneList = CollUtil.newArrayList("ONLINE","OFFLINE");
            // 查询报备信息
            List<MerchantAccessAuthDO> merchantAccessAuthList = getReportRecordList(channelMerchantAccessAuthQueryContext,PayEnums.PAY_TYPE.ALIPAY,sceneList);

            channelMerchantAccessAuthQueryContext.setAuditStatus(MerchantEnum.CHANNEL_CONFIG_STATUS.FINISH);
            channelMerchantAccessAuthQueryContext.setMerchantAccessAuthList(merchantAccessAuthList);
        }
        catch (Exception e) {
            e.printStackTrace();
            log.error("易宝支付宝认证查询查询请求失败,失败信息 message: {}", e.getMessage());
            channelMerchantAccessAuthQueryContext.setRemark("易宝支付宝认证查询查询请求失败,失败信息" + e.getMessage());
            channelMerchantAccessAuthQueryContext.setProcessStatus(Boolean.FALSE);
        }

    }

    @Override
    public MerchantAccessCallBackDto accessCallBackParamsParse(HttpServletRequest request, ProviderChannelConfigDO providerChannelConfigDO) {

        CommonResult<YeePayConfig> yeePayConfigCommonResult = yeePayCommonParamsHandle.yeePayConfig(providerChannelConfigDO,
                true);

        MerchantAccessCallBackDto merchantAccessCallBackDto = new MerchantAccessCallBackDto();
        if (yeePayConfigCommonResult.isSuccess()) {
            YeePayConfig yeePayConfig = yeePayConfigCommonResult.getData();
            // 获取响应内容
            String response = request.getParameter("response");
            if(StrUtil.isNotEmpty(response)){
                String plaintTextWithPrivateKey = null;
                try{
                    // 指定私钥解密
                    plaintTextWithPrivateKey = YeePayRsaUtil.decrypt(response, yeePayConfig,true);
                    log.info("易宝收到回调 plaintTextWithPrivateKey:{}",plaintTextWithPrivateKey);
                    MerchantAccessCallBackResponse callBackResponse = JSONUtil.toBean(plaintTextWithPrivateKey,MerchantAccessCallBackResponse.class);

                    /**
                     * 审核状态转换
                     * 系统审核状态 0：草稿 1：鉴权中 2：已提交，等待平台审核，3：系统自动审核中，4：系统审核通过渠道审核中，5：平台审核中，6：待签约，7：签约中，8：待配置，9：配置中，10：审核完成，11：审核驳回
                     * 易宝进件审核状态如下：
                     * REVIEW_BACK             申请已驳回  -> 审核驳回
                     * AUTHENTICITY_VERIFYING  真实性验证  -> 平台审核中
                     * AGREEMENT_SIGNING       协议待签署  -> 配置中
                     * BUSINESS_OPENING        业务开通中  -> 待签约/签约中
                     * COMPLETED               申请已完成  -> 审核完成
                     */
                    switch (callBackResponse.getApplicationStatus()) {
                        case "REVIEW_BACK":
                            merchantAccessCallBackDto.setAccessStatus(MerchantEnum.ACCESS_STATUS.APPROVE_REFUSE);
                            merchantAccessCallBackDto.setRemark(callBackResponse.getAuditOpinion());
                            break;
                        case "AUTHENTICITY_VERIFYING":
                            merchantAccessCallBackDto.setAccessStatus(MerchantEnum.ACCESS_STATUS.CHANNEL_APPROVE);
                            break;
                        case "AGREEMENT_SIGNING":
                            merchantAccessCallBackDto.setAccessStatus(MerchantEnum.ACCESS_STATUS.WAIT_SIGN);
                            merchantAccessCallBackDto.setAuditStatus(MerchantEnum.CHANNEL_CONFIG_STATUS.CONTINUE_APPLY_QUERY);
                            break;
                        case "BUSINESS_OPENING":
                        case "COMPLETED":
                            merchantAccessCallBackDto.setAccessStatus(MerchantEnum.ACCESS_STATUS.APPROVE_SUCCESS);
                            merchantAccessCallBackDto.setAuditStatus(MerchantEnum.CHANNEL_CONFIG_STATUS.SUBMIT);
                            break;
                        default:
                            merchantAccessCallBackDto.setProcessStatus(false);
                            merchantAccessCallBackDto.setRemark(callBackResponse.getAuditOpinion());
                            break;
                    }
                    merchantAccessCallBackDto.setAgreementSignUrl(callBackResponse.getAgreementSignUrl());
                    merchantAccessCallBackDto.setApplyNo(callBackResponse.getApplicationNo());
                    merchantAccessCallBackDto.setRequestId(callBackResponse.getRequestNo());
                    merchantAccessCallBackDto.setSubMchId(callBackResponse.getMerchantNo());

                }catch (Exception e){
                    e.printStackTrace();
                    merchantAccessCallBackDto.setProcessStatus(false);
                    merchantAccessCallBackDto.setRemark("易宝收到回调 plaintTextWithPrivateKey, 解析失败, msg");
                }
            }
        }
        return merchantAccessCallBackDto;
    }


    /**
     * 商户授权状态查询接口
     */
    @Override
    public Integer queryMerAuthStatus(ChannelMerchantAccessAuthQueryContext channelMerchantAccessAuthQueryContext){

        Integer authStatus = null;
        CommonResult<YeePayConfig> yeePayConfigCommonResult = yeePayCommonParamsHandle.yeePayConfig(channelMerchantAccessAuthQueryContext.getProviderChannelConfig(),
                channelMerchantAccessAuthQueryContext.isTest());
        if (!yeePayConfigCommonResult.isSuccess()) {
            channelMerchantAccessAuthQueryContext.setRemark(yeePayConfigCommonResult.getMsg());
            channelMerchantAccessAuthQueryContext.setProcessStatus(false);
            return null;
        }
        YeePayConfig yeePayConfig = yeePayConfigCommonResult.getData();
        // 数据初始化
        MerchantAccessInfoDO merchantAccessInfo = channelMerchantAccessAuthQueryContext.getMerchantAccessInfo();
        // 授权状态查询配置
        MerchantAuthStatusConfig authStatusConfig = channelMerchantAccessAuthQueryContext.getMerchantAuthStatusConfig();

        try {
            AuthStateQueryV2Request request = new AuthStateQueryV2Request();
            String appKey = yeePayConfig.getAppId();
            request.getRequestConfig().setAppKey(appKey);
            request.getRequestConfig().setCredentials(new YopPKICredentials(
                    appKey, new PKICredentialsItem(getPrivateKey(
                    yeePayConfig.getPrivateKey(),
                    CertTypeEnum.RSA2048),
                    CertTypeEnum.RSA2048)));

            request.setMerchantNo(merchantAccessInfo.getSubMchId());
            request.setFeeType(authStatusConfig.getReportType());
            request.setReportMerchantNo(authStatusConfig.getReportMerchantNo());

            log.info("易宝 查询授权状态 请求参数 :{}", JsonUtils.toJsonString(request));
            AuthStateQueryV2Response response = api.authStateQueryV2(request);
            AuthStateQueryV2IdentityAuthStateResDtoResult result = response.getResult();
            log.info("易宝 查询授权状态 返回参数 :{}", JsonUtils.toJsonString(response.getResult()));
            if ("NIG00000".equals(result.getReturnCode())) {
                List<AuthStateQueryV2IdentityAuthDtoResult> identityAuthDtos = result.getIdentityAuthDtos();
                if(CollUtil.isNotEmpty(identityAuthDtos)){
                    switch (identityAuthDtos.get(0).getAuthorizeState()){
                        case "AUTHORIZE_STATE_UNAUTHORIZED":
                            authStatus = MerchantEnum.AUTH_STATUS_TYPE.UNAUTHORIZED.getCode();
                            break;
                        case "AUTHORIZE_STATE_AUTHORIZED":
                            authStatus = MerchantEnum.AUTH_STATUS_TYPE.AUTHORIZED.getCode();
                            break;
                        case "CLOSED":
                            authStatus = MerchantEnum.AUTH_STATUS_TYPE.CLOSED.getCode();
                            break;
                        case "SMID_NOT_EXIST":
                            authStatus = MerchantEnum.AUTH_STATUS_TYPE.SMID_NOT_EXIST.getCode();
                            break;
                    }
                }
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            log.error("易宝查询授权状态请求失败,失败信息 message: {}", e.getMessage());
        }
        return authStatus;
    }

    @Override
    public CommonResult<String> accessCallbackParse(String callBackBody, List<ProviderChannelConfigDO> channelConfigDOList) {
        return null;
    }

    @Override
    public MerchantBusinessCallBackDto businessCallBackParamsParse(String callBackBody, ProviderChannelConfigDO providerChannelConfigDO) {
        return null;
    }

    @Override
    public boolean verify(String callBackBody, ProviderChannelConfigDO providerChannelConfigDO) {
        return false;
    }

    @Override
    public String callBackResponse(CommonResult commonResult) {
        if (commonResult.isSuccess()) {
            return "SUCCESS";
        }
        else {
            return "FAIL";
        }
    }

    @Override
    public void termAdd(ChannelMerchantTermContext channelMerchantTermContext) {

    }

    @Override
    public void reloadMerchantAuth(ChannelMerchantBusinessContext channelMerchantBusinessContext) {

    }

    @Override
    public void channelSplit(ChannelMerchantBusinessContext channelMerchantBusinessContext) {

    }

    @Override
    public void productUpdate(ChannelMerchantBusinessContext channelMerchantBusinessContext) {

        CommonResult<YeePayConfig> yeePayConfigCommonResult = yeePayCommonParamsHandle.yeePayConfig(channelMerchantBusinessContext.getProviderChannelConfig(),
                channelMerchantBusinessContext.isTest());
        if (!yeePayConfigCommonResult.isSuccess()) {
            channelMerchantBusinessContext.setRemark(yeePayConfigCommonResult.getMsg());
            channelMerchantBusinessContext.setProcessStatus(false);
            return;
        }
        PayChannelRequestDO payChannelRequestDO = new PayChannelRequestDO();
        channelMerchantBusinessContext.setPayChannelRequestDO(payChannelRequestDO);
        YeePayConfig yeePayConfig = yeePayConfigCommonResult.getData();
        MerchantAccessInfoDO merchantAccessInfo = channelMerchantBusinessContext.getMerchantAccessDto().getMerchantAccessInfo();
        MerchantProductReq merchantProductReq = channelMerchantBusinessContext.getMerchantProductReq();
        try {

            String requestNo = merchantAccessInfo.getRequestId();
            if(StrUtil.isEmpty(requestNo)){
                channelMerchantBusinessContext.setRemark("易宝查询进件 参数 requestNo is null");
                channelMerchantBusinessContext.setProcessStatus(false);
                return;
            }

            ProductFeeModifyV2Request request = new ProductFeeModifyV2Request();
            String appKey = yeePayConfig.getAppId();
            request.getRequestConfig().setAppKey(appKey);
            request.getRequestConfig().setCredentials(new YopPKICredentials(
                    appKey, new PKICredentialsItem(getPrivateKey(
                    yeePayConfig.getPrivateKey(),
                    CertTypeEnum.RSA2048),
                    CertTypeEnum.RSA2048)));

            request.setRequestNo(requestNo);
            request.setMerchantNo(merchantAccessInfo.getSubMchId());
            request.setNotifyUrl(channelMerchantBusinessContext.getAsyncReturnUrl());

            // 获取需要更新的功能
            List<MerchantProductInfo> productInfos = merchantProductReq.getFeeInfo();
            // 分组
            Map<Integer, List<MerchantProductInfo>> productInfoMap = productInfos.stream().collect(Collectors.groupingBy(MerchantProductInfo::getPaySence));
            // 遍历
            productInfoMap.forEach((sence, value) -> {
                switch (PayOrderEnums.PAY_FUNCTION_SENCE_TYPE.from(sence)){
                    // 分账
                    case SHARE:
                        List<String> functionService  = new ArrayList<>();
                        functionService.add("SHARE");
                        request.setFunctionService(JSONUtil.toJsonStr(functionService));
                        // 分账资质
                        Map<String,String> qualificationInfo = new HashMap<>();
                        qualificationInfo.put("shareScene","FZ_ALL001");
                        request.setFunctionServiceQualificationInfo(JSONUtil.toJsonStr(qualificationInfo));
                        break;
                    // 产品
                    case PRODUCT:
                        break;
                }
            });

            log.info("易宝产品变更 请求参数 :{}", JsonUtils.toJsonString(request));
            ProductFeeModifyV2Response response = api.productFeeModifyV2(request);
            ProductFeeModifyV2ModifyProductFeeRespDtoResult result = response.getResult();
            log.info("易宝产品变更 返回参数 :{}", JsonUtils.toJsonString(response.getResult()));

            if("NIG00000".equals(result.getReturnCode())){
                log.info("易宝产品变更 成功 返回参数 :{}", JsonUtils.toJsonString(result));
            }else{
                channelMerchantBusinessContext.setProcessStatus(Boolean.FALSE);
                channelMerchantBusinessContext.setRemark(result.getReturnMsg());
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            channelMerchantBusinessContext.setRemark("易宝产品变更请求失败,失败信息" + e.getMessage());
            channelMerchantBusinessContext.setProcessStatus(Boolean.FALSE);
        }

    }

    @Override
    public MerchantProductQueryResp productQuery(ChannelMerchantBusinessContext channelMerchantBusinessContext) {

        CommonResult<YeePayConfig> yeePayConfigCommonResult = yeePayCommonParamsHandle.yeePayConfig(channelMerchantBusinessContext.getProviderChannelConfig(),
                channelMerchantBusinessContext.isTest());
        if (!yeePayConfigCommonResult.isSuccess()) {
            channelMerchantBusinessContext.setRemark(yeePayConfigCommonResult.getMsg());
            channelMerchantBusinessContext.setProcessStatus(false);
            return null;
        }
        PayChannelRequestDO payChannelRequestDO = new PayChannelRequestDO();
        channelMerchantBusinessContext.setPayChannelRequestDO(payChannelRequestDO);
        YeePayConfig yeePayConfig = yeePayConfigCommonResult.getData();
        MerchantAccessInfoDO merchantAccessInfo = channelMerchantBusinessContext.getMerchantAccessDto().getMerchantAccessInfo();
        try {
            String requestNo = merchantAccessInfo.getRequestId();
            if(StrUtil.isEmpty(requestNo)){
                channelMerchantBusinessContext.setRemark("易宝查询进件 参数 requestNo is null");
                channelMerchantBusinessContext.setProcessStatus(false);
                return null;
            }

            ProductModifyQueryV2Request request = new ProductModifyQueryV2Request();
            String appKey = yeePayConfig.getAppId();
            request.getRequestConfig().setAppKey(appKey);
            request.getRequestConfig().setCredentials(new YopPKICredentials(
                    appKey, new PKICredentialsItem(getPrivateKey(
                    yeePayConfig.getPrivateKey(),
                    CertTypeEnum.RSA2048),
                    CertTypeEnum.RSA2048)));

            request.setRequestNo(requestNo);

            log.info("易宝产品变更状态查询 请求参数 :{}", JsonUtils.toJsonString(request));
            ProductModifyQueryV2Response response = api.productModifyQueryV2(request);
            ProductModifyQueryV2ProductModifyProgressQueryRespDtoResult result = response.getResult();
            log.info("易宝产品变更状态查询 返回参数 :{}", JsonUtils.toJsonString(response.getResult()));

            if("NIG00000".equals(result.getReturnCode())){
                // 审核中：REVIEWING 待签署：SIGNING  驳回：REVIEW_BACK 完成：COMPLETED
                MerchantProductQueryResp resp = new MerchantProductQueryResp();
                switch (result.getApplicationStatus()) {
                    case "REVIEW_BACK":
                        resp.setStatus("REVIEW_BACK");
                        resp.setDescription(result.getAuditOpinion());
                        break;
                    case "AUTHENTICITY_VERIFYING":
                        resp.setStatus("SIGNING");
                        resp.setDescription(result.getReturnMsg());
                        resp.setSignUrl(result.getIntentionAuthUrl());
                        break;
                    case "AGREEMENT_SIGNING":
                        resp.setStatus("SIGNING");
                        resp.setDescription(result.getReturnMsg());
                        resp.setSignUrl(result.getElecSignUrl());
                        break;
                    case "COMPLETED":
                        resp.setStatus("COMPLETED");
                        resp.setDescription(result.getAuditOpinion());
                        break;
                }
                return resp;
            }else{
                channelMerchantBusinessContext.setProcessStatus(Boolean.FALSE);
                channelMerchantBusinessContext.setRemark(result.getReturnMsg());
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            channelMerchantBusinessContext.setRemark("易宝产品变更状态查询请求失败,失败信息" + e.getMessage());
            channelMerchantBusinessContext.setProcessStatus(Boolean.FALSE);
        }
        return null;
    }

    @Override
    public MerchantChannelSplitCallBackDto easySplitCallBackParamsParse(HttpServletRequest request, ProviderChannelConfigDO providerChannelConfigDO) {
        return null;
    }

    public static void main(String[] args) {


        YeePayConfig yeePayConfig = new YeePayConfig();
        yeePayConfig.setAppId("app_10089798423");
        yeePayConfig.setMchId("10089798423");
        yeePayConfig.setPrivateKey("MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCbpEqTMdaC6cciHsTMv+8eeUAFmoLt97D4r+c6X1Yz2FPjGrlcz5qqr1L7ZL9EL8/bZnb4C1e17Y3QOnW3LKO1xNIO08kXdbeSfWbY08ssGPSbTE28OFMn92Zl80ldQeppKTEcrxwkwQtuP2oplyn+LapjEc0FYDetvc8LeSBxd9lS+EVyUa+Rx3a14vi65ELw61tOzbUi4bEseUJMRjhfkATtRrHM6jtKoSe9b3PVKdnUE+XH2ZYG+4e4eOOcw2o9AdBX/yU4r9Z8t2pEiLFF2RT6h8uFtb6sS9gdB1chU4mdo6pdB037io8FwNKA3mFYhDNau08BYAeHSEvQNxKhAgMBAAECgf9s03NReIeFAfE66kiw4YNQy3b4dBEYUxhqypPjPMYJejktkoIJYx/CONTM8qTKCKRNxFdrGIM7sd52ummUqqHNdtFpjKwOu0CgLQ68jVqCevCNpcy0zq1WRKZUosepbW16GlM8uzPyfwh/DdgtPIUgNM3ud4PjPmOwGAes/gSxUQObFvu9eEaLkgb0TwRXZYd1N02M7xkPXUcLG4Ls/NV0xZ+zPxNl7JXVnFf0gp6O0CRyuRnwLRjwEBbKb5rbkgG47b9/44o4ma3HVyqZhhA7WrTlY38xeW4lVVqsACJ1LJl2uioQnSedOpH8QIsANZV7F8hWgqgkncEUFwsE7xECgYEA2Dh2gN24SPEO4qsiBkHmeGJJzwVKGeMNJxpSDYJ0X03k11Fwno+mY5BUPFSH+5deZvs+trte4nu519w0ltme678smfrYbSDIyg7w630eLgz8w+hFe1xo496cnQ2mIIwp2fySXNWLJHUyWeGR/nCRl27496pJM9yLo5HxbkHx16UCgYEAuEaxjQwVzZQR3DrmLC4H/NI2oKS0vCbbNRudHduyumacwxngaCCpaIUam/D6q6FJu2l43gOAXwBNFwq2JbpPl9Df+x1QIzLgCnTmCZc7zIKhxI6MHrQRU3sSoJgrJMPqrUlcNBVjiQUUudc1OT5raojBM+wYA1Oie0cU52kefk0CgYBZ2czU7E5CcXoAE6GF/Cir6hxF3SrX6xRyJWvnlUiKujHYkE0+du9r/HQkxfPkRxjBrrJ2+RILB+NIoodwEGsMCFueeTEq2C7YWLEhCtNZy6fWOVV2WAZ2evGWCi/44oYZwe2IimzR76nG1Af5NgoqZcEsGiVlWcblaCZt7RV0yQKBgQCcwdZsC+nINbtzws7mqkm1MgWyZioxHETBSro/GhNSKdQUy8BwE8jI1uGp4jb7JXsZaEGfaw8awaDShxQnx/PJS7AdZ/Qx3Sdk/chqRDJkaIPANxrPS5KplzpjTs70uYy62HsM+1zuxFm7NW1bQtQRjj/8MUzEF7NSd0c7C9sayQKBgQCyKawGfP/NeLdfrOVJ8QYI02AjFkGQWfPGT58FRHRiGdzcqzK9h5ZhRyMNr1qRZ09ZLgcDEVCCOq58hdC8YY8wUyWE5/4+TYgfKRt4J2S8AXQ5roAVXcn7e+CFQarqGrMRtoVR6uTPH0BvGQNNd+O0w6Zfz6zDVn4cF1ir+dbStA==");
        yeePayConfig.setPublicKey("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA6p0XWjscY+gsyqKRhw9MeLsEmhFdBRhT2emOck/F1Omw38ZWhJxh9kDfs5HzFJMrVozgU+SJFDONxs8UB0wMILKRmqfLcfClG9MyCNuJkkfm0HFQv1hRGdOvZPXj3Bckuwa7FrEXBRYUhK7vJ40afumspthmse6bs6mZxNn/mALZ2X07uznOrrc2rk41Y2HftduxZw6T4EmtWuN2x4CZ8gwSyPAW5ZzZJLQ6tZDojBK4GZTAGhnn3bg5bBsBlw2+FLkCQBuDsJVsFPiGh/b6K/+zGTvWyUcu+LUj2MejYQELDO3i2vQXVDk7lVi2/TcUYefvIcssnzsfCfjaorxsuwIDAQAB");

        // YopClient yopClient = YopClientBuilder.builder().withEndpoint("https://openapi.yeepay.com/yop-center").build();
        // YopRequest request = new YopRequest("/yos/v1.0/sys/merchant/qual/upload", "POST");
        // String appKey = yeePayConfig.getAppId();
        // request.getRequestConfig().setAppKey(appKey);
        // request.getRequestConfig().setSecurityReq("YOP-RSA2048-SHA256");
        // request.getRequestConfig().setCredentials(new YopPKICredentials(
        //         appKey, new PKICredentialsItem(getPrivateKey(
        //         yeePayConfig.getPrivateKey(),
        //         CertTypeEnum.RSA2048)
        //         , CertTypeEnum.RSA2048)));
        //
        //
        // request.addMultiPartFile("merQual", FileUtil.getInputStream("E:\\soft_img\\test.png"));
        // YopResponse resp = yopClient.request(request);
        // System.out.println(JSONUtil.toJsonStr(resp));


        SysClient api = SysClientBuilder.builder().build();

        MerchantQualUploadRequest request = new MerchantQualUploadRequest();

        String appKey = yeePayConfig.getAppId();
        request.getRequestConfig().setAppKey(appKey);
        request.getRequestConfig().setCredentials(new YopPKICredentials(
                appKey, new PKICredentialsItem(getPrivateKey(
                yeePayConfig.getPrivateKey(),
                CertTypeEnum.RSA2048)
                , CertTypeEnum.RSA2048)));
        request.setMerQual(new File("E:\\soft_img\\test.png"));
        MerchantQualUploadResponse response = api.merchantQualUpload(request);
        log.info("result:{}", response.getResult());



    }

    private static  PrivateKey getPrivateKey(String priKey, CertTypeEnum certType) {
        final YopCertConfig yopCertConfig = new YopCertConfig();
        yopCertConfig.setCertType(certType);
        yopCertConfig.setValue(priKey);
        yopCertConfig.setStoreType(CertStoreType.STRING);
        return (PrivateKey) YopCertParserFactory.getCertParser(YopCertCategory.PRIVATE, certType).parse(yopCertConfig);
    }


    /**
     * 获取报备记录
     * @param payType   支付类型 微信、支付宝
     * @param sceneList 场景 线上、线下
     * @return
     */
    private List<MerchantAccessAuthDO> getReportRecordList(ChannelMerchantAccessAuthQueryContext channelMerchantAccessAuthQueryContext,PayEnums.PAY_TYPE payType,List<String> sceneList){
        // 查询报备信息
        List<MerchantAccessAuthDO> merchantAccessAuthList = new ArrayList<>();
        CommonResult<YeePayConfig> yeePayConfigCommonResult = yeePayCommonParamsHandle.yeePayConfig(channelMerchantAccessAuthQueryContext.getProviderChannelConfig(),
                channelMerchantAccessAuthQueryContext.isTest());
        if (!yeePayConfigCommonResult.isSuccess()) {
            channelMerchantAccessAuthQueryContext.setRemark(yeePayConfigCommonResult.getMsg());
            channelMerchantAccessAuthQueryContext.setProcessStatus(false);
            return merchantAccessAuthList;
        }
        YeePayConfig yeePayConfig = yeePayConfigCommonResult.getData();
        MerchantAccessInfoDO merchantAccessInfo = channelMerchantAccessAuthQueryContext.getMerchantAccessInfo();
        try{
            ReportQueryRequest request = null;
            for(String scene:sceneList){
                request = new ReportQueryRequest();
                String appKey = yeePayConfig.getAppId();
                request.getRequestConfig().setAppKey(appKey);
                request.getRequestConfig().setCredentials(new YopPKICredentials(
                        appKey, new PKICredentialsItem(getPrivateKey(
                        yeePayConfig.getPrivateKey(),
                        CertTypeEnum.RSA2048),
                        CertTypeEnum.RSA2048)));
                request.setChannel(payType.getType());
                request.setMerchantNo(merchantAccessInfo.getSubMchId());
                request.setScene(scene);

                log.info("易宝  "+payType.getType()+ " 报备查询 请求参数 :{}", JsonUtils.toJsonString(request));
                ReportQueryResponse response = aggpayApi.reportQuery(request);
                ReportRecordQueryResponseDTO result =  response.getResult();
                log.info("易宝  "+payType.getType()+ " 报备查询 返回参数 :{}", JsonUtils.toJsonString(result));

                if ("00000".equals(result.getCode())) {
                    MerchantAccessAuthDO merchantAccessAuthDO = new MerchantAccessAuthDO();
                    merchantAccessAuthDO.setType(payType.getCode());
                    merchantAccessAuthDO.setSn(merchantAccessInfo.getSn());
                    merchantAccessAuthDO.setAccessId(merchantAccessInfo.getId());
                    // 报备JSON
                    String reportRecordJson = result.getReportRecordList();
                    if(StrUtil.isEmpty(reportRecordJson)){
                        continue;
                    }
                    // 报备记录集合
                    List<YeePayReportRecord> reportRecordList = JSONUtil.toList(reportRecordJson, YeePayReportRecord.class);
                    if (CollUtil.isNotEmpty(reportRecordList)) {
                        for (YeePayReportRecord reportRecord : reportRecordList) {
                            // 过滤 非此 scene 条件
                            if(!reportRecord.getScene().equals(scene)){
                                continue;
                            }
                            switch (reportRecord.getReportStatus()) {
                                case "FAILED":
                                    merchantAccessAuthDO.setStatus(MerchantEnum.MERCHANT_AUTH_STATUS.REJECT.getCode());
                                    break;
                                case "AUDITING":
                                    merchantAccessAuthDO.setStatus(MerchantEnum.MERCHANT_AUTH_STATUS.APPROVEING.getCode());
                                    break;
                                case "SUCCESS":
                                    merchantAccessAuthDO.setStatus(MerchantEnum.MERCHANT_AUTH_STATUS.APPROVE.getCode());
                                    break;
                                case "INIT":
                                    merchantAccessAuthDO.setStatus(MerchantEnum.MERCHANT_AUTH_STATUS.NO_APPLY.getCode());
                                    break;
                                default:
                            }
                            merchantAccessAuthDO.setSubMchId(reportRecord.getReportMerchantNo());
                            merchantAccessAuthDO.setMchId(reportRecord.getChannelNo());
                            merchantAccessAuthDO.setRejectReason(reportRecord.getFailReason());

                            // 异步查询授权状态
                            String feeType = null;
                            switch (payType){
                                case WECHAT:
                                    if(scene.equals("ONLINE")){
                                        feeType = "XIANSHANG";
                                    }else if(scene.equals("OFFLINE")){
                                        feeType = "XIANXIA";
                                    }
                                    break;
                                case ALIPAY:
                                    feeType = "ALIPUTONG";
                                    break;
                            }

                            // 异步更新授权状态
                            MerchantAuthStatusConfig merchantAuthStatusConfig = new MerchantAuthStatusConfig();
                            merchantAuthStatusConfig.setReportType(feeType);
                            merchantAuthStatusConfig.setReportMerchantNo(reportRecord.getReportMerchantNo());
                            merchantAuthStatusConfig.setAccessId(merchantAccessInfo.getId());
                            merchantAccessStatusProcessHandler.processAuthAccess(merchantAuthStatusConfig);
                            merchantAccessAuthList.add(merchantAccessAuthDO);
                        }
                    }
                }else{
                    log.info("易宝 "+payType.getType()+ " 报备查询 返回异常 :{}", JsonUtils.toJsonString(response));
                }
            }
        }catch (Exception e){
            e.printStackTrace();
            log.error("易宝 "+payType.getType()+ " 报备查询查询请求失败,失败信息 message: {}", e.getMessage());
        }
        // 去重
        if(merchantAccessAuthList.size() > 1){
            merchantAccessAuthList = CollUtil.distinct(merchantAccessAuthList,e -> e.getSubMchId(),true);
        }
        return merchantAccessAuthList;
    }




}
